<?php
/**
 *
 *
 * @package    channel 
 * @author     qiulf <qiulf@gmail.com>
 * @copyright  2009 fengone.com
 * @created    2010-07-25 16:11:35.
 * @version    $Id: xmlParse.class.php 2908 2013-04-10 10:43:06Z qiulf $
 * SVNPath     $HeadURL: http://svn.ladyol.cn/fcms/branches/wj/www.mubook.com/libs/core/channel/xmlParse.class.php $         
 */

//defined('APP') || exit('Access Denied!');

class xmlParse {
    public $xml;

    public function __construct($f) {
        if (is_file($f)) {
            $this->xml = simplexml_load_file($f);
        } else {
            $this->xml = simplexml_load_string($f);
        }
    }

    public function loadBillid() {
        $o = $this->xml;
        $mailNum = "";
        if (!empty($o->mailnum)) {
            $mailNum = (string)$o->mailnum;
        }
        return $mailNum;
    }

    public function cancelBillid() {
        $o = $this->xml;
        $status = false;
        if (!empty($o->status) && (string)$o->status == "success") {
            $status = true;
        }
        return $status;
    }

    public function loadTrackMessage() {
        $o = $this->xml;
        $track = array();
        if (!empty($o->trace)) {
            foreach ($o->trace as $t) {
                $track[] = array(
                    "acceptTime"    => (string)$t->acceptTime,
                    "acceptAddress" => (string)$t->acceptAddress,
                    "remark" => (string)$t->remark,
                );   
            }
        }
        return $track;
    }

    public function loadFee() {
        $o = $this->xml;
        $fee = array();
        if (!empty($o)) {
            $fee['weight']      = (string)$o->weight;
            $fee['recvcountry'] = (string)$o->recvcountry;
            $fee['sendcountry'] = (string)$o->sendcountry;
            $fee['fee']         = (string)$o->fee;
        }
        return $fee;
    }

    public function loadDistrict() {
        $o = $this->xml;
        $district = array();
        $pid = 0;
        foreach ($o->attributes() as $k => $v) {
            $pid = (string)$v;
        }
        foreach ($o->area as $k => $r) {
            $district[$pid][] = array(
                "code" => (string)$r->attributes(),
                "name" => (string)$r[0]
            );
        }
        return $district;
    }
}
